<template>
  <div>
    <!-- 头部 -->
    <van-nav-bar title="外卖项目" left-arrow fixed z-index="999" @click-left="refresh" @click-right="Login" placeholder :border="false">
      <template #left>
        <div class="rightText">ele.me</div>
      </template>
      <template #right>
        <div class="rightText">登录|注册</div>
      </template>
    </van-nav-bar>
    <!-- 当前定位城市 -->
    <nav class="city_nav">
      <div class="city_tip">
        <span>当前定位城市：</span>
        <span>定位不准时，请在城市列表中选择</span>
      </div>
      <div class="guess_city" @click="specificCity(positioningCity)">
        <span v-if="positioningCity.name">{{positioningCity.name}}</span>
        <van-icon name=" arrow" color="#bbbbbb" />
      </div>
    </nav>
    <!-- 热门城市 -->
    <section class="hot_city_container">
      <h4 class="city_title">热门城市</h4>
      <ul class="citylistul">
        <li v-for="item in cityData" :key="item.id" @click="specificCity(item)">{{item.name}}</li>
      </ul>
    </section>
    <!-- 字母排序 -->
    <section class="group_city_container">
      <ul class="letter_classify" v-if="AllCity">
        <msiteList v-for="(item,index) in AllCity" :key="index" :msiteData="item" :index="index">
        </msiteList>
      </ul>
    </section>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import msiteList from '@/views/Home/msiteList/msiteList.vue'
export default {
  components: {
    msiteList
  },
  computed: {
    ...mapState(['positioningCity', 'cityData', 'AllCity'])
  },
  methods: {
    // 点击左侧网址刷新
    refresh() {
      this.$router.go(0)
    },
    // 点击右侧跳转至登录
    Login() {
      this.$router.push('/login')
    },
    // 跳转搜索地址
    specificCity(i) {
      if (i.id) {
        window.sessionStorage.setItem('city_id', i.id)
        window.sessionStorage.setItem('city_title', i.name)
        this.$router.push(`/city/${i.id}`)
      }
    }
  },
  mounted() {
    this.$store.dispatch('Getcity')
    this.$store.dispatch('Getcity1')
  }
}
</script>

<style lang="less" scoped>
.rightText {
  color: #fff;
}
.city_nav {
  padding-top: 0.2rem;
  border-top: 1px solid #e4e4e4;
  background-color: #fff;
  margin-bottom: 0.4rem;
  .city_tip {
    display: flex;
    justify-content: space-between;
    line-height: 1.45rem;
    padding: 0 0.45rem;
    span:first-of-type {
      font-size: 0.55rem;
      color: #666;
    }
    span:nth-of-type(2) {
      font-weight: 900;
      color: #9f9f9f;
    }
  }
  .guess_city {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 1.8rem;
    padding: 0 0.45rem;
    border-top: 1px solid #e4e4e4;
    border-bottom: 2px solid #e4e4e4;
    font-size: 0.68rem;
    span:first-of-type {
      color: #3190e8;
    }
  }
}
.hot_city_container {
  background-color: #fff;
  margin-bottom: 0.4rem;
}
</style>